//
//  jViewController.m
//  JBrowserSDK
//
//  Created by jhfappkf@163.com on 01/04/2018.
//  Copyright (c) 2018 jhfappkf@163.com. All rights reserved.
//

#import "jViewController.h"
#import <JPhotoBrowser/JPhotoBrowser.h>

@interface jViewController ()<JPhotoBrowserDelegate>

@end

@implementation jViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)url:(id)sender {
    
    NSMutableArray <JPhotoItem *>*items = [NSMutableArray array];
    JPhotoItem *item;
    [[self imageUrls] enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        JPhotoItem *item = [[JPhotoItem alloc] initWithSourceView:self.imageview imageUrl:[NSURL URLWithString:obj]];
        [items addObject:item];
    }];
    item = [[JPhotoItem alloc] initWithSourceView:self.imageview thumbImageUrl:[NSURL URLWithString:@"https://ss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/449.jpg"] videoUrl:[NSURL URLWithString:@"http://www.w3school.com.cn/example/html5/mov_bbb.mp4"]];
    [items addObject:item];
    JPhotoBrowser *browser = [[JPhotoBrowser alloc] initWithPhotoItems:items selectedIndex:0];
    browser.delegate = self;
    browser.bounces = NO;
    browser.dismissalStyle = JPhotoBrowserInteractiveDismissalStyleScale;
    [browser showFromViewController:self];
    
}


- (void)j_photoBrowser:(JPhotoBrowser *)browser didSelectItem:(JPhotoItem *)item atIndex:(NSUInteger)index; {
    NSLog(@"%ld",index);
}

- (NSArray <NSString *>*)imageUrls{
    NSMutableArray *array = [NSMutableArray array];
    [array addObject:@"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3445497520,1801625963&fm=27&gp=0.jpg"];
    for (int i = 0; i < 10; i++) {
        [array addObject:[NSString stringWithFormat:@"https://ss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/%d.jpg",449 + i]];
    }
    [array addObject:@"https://pic2.zhimg.com/v2-19169fea7463f3324ae00ab9bf2fbc75_b.gif"];
    return array.copy;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
